{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0ff14e39-ae77-432b-b327-c2ce880b0ede",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "1*2=2\t2*2=4\t\n",
      "1*3=3\t2*3=6\t3*3=9\t\n",
      "1*4=4\t2*4=8\t3*4=12\t4*4=16\t\n",
      "1*5=5\t2*5=10\t3*5=15\t4*5=20\t5*5=25\t\n",
      "1*6=6\t2*6=12\t3*6=18\t4*6=24\t5*6=30\t6*6=36\t\n",
      "1*7=7\t2*7=14\t3*7=21\t4*7=28\t5*7=35\t6*7=42\t7*7=49\t\n",
      "1*8=8\t2*8=16\t3*8=24\t4*8=32\t5*8=40\t6*8=48\t7*8=56\t8*8=64\t\n",
      "1*9=9\t2*9=18\t3*9=27\t4*9=36\t5*9=45\t6*9=54\t7*9=63\t8*9=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(1,i+1):\n",
    "        print(f\"{j}*{i}={j*i}\",end=\"\\t\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "22084498-069f-4189-a7f5-9c403d28b75c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst = list(range(10,20))\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "383272c7-e499-40a5-852e-ad15c7759daf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10, 20, 30, 40, 50, 60, 70, 80, 90]\n",
      "1\n",
      "80\n",
      "30\n",
      "[10, 20, 30, 50, 60, 70, 80, 90]\n",
      "[10, 50, 60, 70, 80, 90]\n"
     ]
    }
   ],
   "source": [
    "lst = [i*10 for i in range(1,10)]\n",
    "print(lst)\n",
    "print(lst.index(20))\n",
    "# print(lst.find(20))\n",
    "print(lst[-2])\n",
    "print(lst[2])\n",
    "# lst.remove(200)\n",
    "# print(lst)\n",
    "lst.pop(3)\n",
    "print(lst)\n",
    "lst[1:3] = []\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9ae8132c-629d-44b1-9b2d-95eaa02da9f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 11, 22, 33, 2, 3]\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "lst1 = [1,2,3]\n",
    "lst2 = [11,22,33]\n",
    "lst1[1:1] = lst2\n",
    "print(lst1)\n",
    "print(lst[1:1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "afbd999e-eb99-4449-b860-6b4b65ee3891",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 10, 100]\n"
     ]
    }
   ],
   "source": [
    "lst = [1,2,3,4,5,6,7,10,101,100]\n",
    "lst1 = [x for x in lst if x%2==0]\n",
    "print(lst1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "5430bc6a-20f8-4159-b799-1c8d988142ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 3, 16, 5, 36, 7, 100, 101, 10000]\n"
     ]
    }
   ],
   "source": [
    "lst2 = [x**2 if x%2==0 else x for x in lst]\n",
    "print(lst2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "61f635c1-bb14-4154-826d-99323aa1dfdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 2, 0, 4, 0, 6, 0, 10, 0, 100]\n"
     ]
    }
   ],
   "source": [
    "lst1 = [x if x%2==0 else 0 for x in lst]\n",
    "print(lst1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "33245c31-6920-4513-ab3b-e6016bb8cddd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 10, 100]\n"
     ]
    }
   ],
   "source": [
    "lst2 = [x for x in lst if x%2==0]\n",
    "print(lst2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "632b0096-669c-41cc-a37d-183fda66f085",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2302430066432 <class 'dict'>\n",
      "张三\n",
      "{'name': '张三', 'age': 22, 'gender': '女'}\n",
      "None\n",
      "dict_keys(['name', 'age', 'gender'])\n",
      "['name', 'age', 'gender']\n",
      "['张三', 22, '女']\n",
      "dict_items([('name', '张三'), ('age', 22), ('gender', '女')])\n",
      "name 张三\n",
      "age 22\n",
      "gender 女\n"
     ]
    }
   ],
   "source": [
    "d = {\"name\":\"张三\",\"age\":22}\n",
    "print(id(d),type(d))\n",
    "print(d[\"name\"])\n",
    "m1 = dict(name=\"张三\",age=22,gender=\"女\")\n",
    "print(m1)\n",
    "# print(m1[\"aa\"])\n",
    "print(m1.get(\"aa\"))\n",
    "print(m1.keys())\n",
    "print(list(m1.keys()))\n",
    "print(list(m1.values()))\n",
    "print(m1.items())\n",
    "for it in m1.items():\n",
    "    print(it[0],it[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "68bbbabc-421d-4437-bf6b-55b53430c072",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(1, 'a'), (2, 'b'), (3, 'c')]\n"
     ]
    }
   ],
   "source": [
    "lst1 = [1,2,3]\n",
    "lst2 = ['a','b','c']\n",
    "item = list(zip(lst1,lst2))\n",
    "print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "642d393b-e8b5-4a9b-b373-0c4a47b9bb65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 'a', 2: 'b', 3: 'c'}\n"
     ]
    }
   ],
   "source": [
    "d = {a:b for a,b in zip(lst1,lst2)}\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "2c6113b9-3599-463c-a000-7bb102e11c29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2302429538496 [1, 2, 3, 4, 5]\n",
      "2302429538496 [1, 2, 3, 4, 5, 3]\n",
      "hello 2302404338544\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'append'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[52], line 9\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[38;5;28mprint\u001b[39m(s1,\u001b[38;5;28mid\u001b[39m(s1))\n\u001b[0;32m      8\u001b[0m \u001b[38;5;66;03m# s1+=\"a\"\u001b[39;00m\n\u001b[1;32m----> 9\u001b[0m \u001b[43ms1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     10\u001b[0m \u001b[38;5;28mprint\u001b[39m(s1,\u001b[38;5;28mid\u001b[39m(s1))\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'append'"
     ]
    }
   ],
   "source": [
    "lst = [1,2,3,4,5]\n",
    "print(id(lst),lst)\n",
    "lst.append(3)\n",
    "print(id(lst),lst)\n",
    "\n",
    "s1 = \"hello\"\n",
    "print(s1,id(s1))\n",
    "# s1+=\"a\"\n",
    "# s1.append(\"a\")\n",
    "print(s1,id(s1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "8a8ff75c-f7a6-4e3c-8b89-3b2ae5edd44c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2302408437328 <class 'tuple'>\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'tuple' object has no attribute 'append'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[53], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m a \u001b[38;5;241m=\u001b[39m (\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m4\u001b[39m)\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mid\u001b[39m(a),\u001b[38;5;28mtype\u001b[39m(a))\n\u001b[1;32m----> 3\u001b[0m \u001b[43ma\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;241m2\u001b[39m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
     ]
    }
   ],
   "source": [
    "a = (1,2,3,4)\n",
    "print(id(a),type(a))\n",
    "# a.append(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "e7599614-58ff-4123-9816-a5ddf428fbb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4, 5} <class 'set'>\n",
      "{65, 1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "s3 = set([1,2,3,3,3,4,5])\n",
    "print(s3,type(s3)) #{1, 2, 3, 4, 5} <class 'set'>\n",
    "\n",
    "s4 = set((2,3,1,2,1,2,65))\n",
    "print(s4) #{65, 1, 2, 3}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "2d2f8944-cc84-43ea-8665-8f2f67d897e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{5}\n",
      "{1, 2, 5}\n"
     ]
    }
   ],
   "source": [
    "a = {1,2,3,4}\n",
    "b = {3,4,5}\n",
    "print(b-a)\n",
    "print(a.symmetric_difference(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "b8eb1350-a34f-4d49-9f30-9f4d5fedc597",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 64, 4, 36, 9, 16, 49, 81, 25}\n"
     ]
    }
   ],
   "source": [
    "s = {i*i for i in range(10)}\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "55b205ee-ae2e-4fe9-b09c-cc9dacb36514",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "'function call' is an illegal expression for augmented assignment (3158516830.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[59], line 5\u001b[1;36m\u001b[0m\n\u001b[1;33m    d.get(s)+=1\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m 'function call' is an illegal expression for augmented assignment\n"
     ]
    }
   ],
   "source": [
    "s1 = \"sadflkajsfl29u3rlksdnfkalsndfkjhdf\"\n",
    "d = {}\n",
    "for s in s1:\n",
    "    if s in d:\n",
    "        d[]+=1\n",
    "    else:\n",
    "        d.get(s) = \n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "19a2303e-278f-42f1-b475-3543ed91f0cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "6\n",
      "-1\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "substring not found",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[5], line 5\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mstr\u001b[39m\u001b[38;5;241m.\u001b[39mindex(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwor\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mstr\u001b[39m\u001b[38;5;241m.\u001b[39mfind(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m222\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mstr\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindex\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m222\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n",
      "\u001b[1;31mValueError\u001b[0m: substring not found"
     ]
    }
   ],
   "source": [
    "str = \"hello world\"\n",
    "print(str.find(\"world\"))\n",
    "print(str.index(\"wor\"))\n",
    "print(str.find(\"222\"))\n",
    "print(str.index(\"222\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6f3049b9-6bd1-4b7c-b761-cf16d6c835ab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "张三     \t计算机科学技术        \t物理与信息     \n",
      "李四     \t中文系            \t人文学院      \n",
      "王五啊    \t计算机科学技术        \t计算机科学学院   \n"
     ]
    }
   ],
   "source": [
    "format_title = '{:<7}\\t{:<15}\\t{:<10}'\n",
    "print(format_title.format(\"张三\",\"计算机科学技术\",\"物理与信息\"))\n",
    "print(format_title.format(\"李四\",\"中文系\",\"人文学院\"))\n",
    "print(format_title.format(\"王五啊\",\"计算机科学技术\",\"计算机科学学院\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f239636-733d-43ab-9728-c736bc803b37",
   "metadata": {},
   "source": [
    "stu = {\"name\":\"张三\",\"no\":\"001\",\"age\":12,\"major\":\"计算机科学技术\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38667ef4-129e-440b-842c-8be6d438cdc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请选择一个正确操作\n",
      "添加(A)\t删除(D)\t修改(U)\t查询(Q)\t列表(L)\t退出(E)\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请选择一个操作: a\n",
      "请输入学号: 001\n",
      "请输入姓名: aaa\n",
      "请输入年龄: 23\n",
      "请输入专业: aaa\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=============>添加学生成功<===============\n",
      "请选择一个正确操作\n",
      "添加(A)\t删除(D)\t修改(U)\t查询(Q)\t列表(L)\t退出(E)\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请选择一个操作: l\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------------------------------------------------------------\n",
      "学号     \t姓名        \t年龄        \t专业             \n",
      "001       \taaa         \t23        \taaa            \n",
      "----------------------------------------------------------------------\n",
      "请选择一个正确操作\n",
      "添加(A)\t删除(D)\t修改(U)\t查询(Q)\t列表(L)\t退出(E)\n"
     ]
    }
   ],
   "source": [
    "stu_list = []\n",
    "format_title = '{:<7}\\t{:<10}\\t{:<10}\\t{:<15}'\n",
    "format_data = '{:<10}\\t{:<12}\\t{:<10}\\t{:<15}'\n",
    "\n",
    "# print(format_title.format(\"学号\",\"姓名\",\"年龄\",\"专业\"))\n",
    "# print(format_data.format(\"001\",\"张但是三\",22,\"计算机科学技术\"))\n",
    "\n",
    "def show_operator():\n",
    "    print(\"请选择一个正确操作\")\n",
    "    print(\"添加(A)\\t删除(D)\\t修改(U)\\t查询(Q)\\t列表(L)\\t退出(E)\")\n",
    "def add():\n",
    "    no = input(\"请输入学号:\")\n",
    "    name = input(\"请输入姓名:\")\n",
    "    age = int(input(\"请输入年龄:\"))\n",
    "    major = input(\"请输入专业:\")\n",
    "    stu = {\"no\":no,\"name\":name,\"age\":age,\"major\":major}\n",
    "    stu_list.append(stu)\n",
    "    print(\"=============>添加学生成功<===============\")\n",
    "def load_stu(no):\n",
    "    for stu in stu_list:\n",
    "        if(stu[\"no\"]==no):\n",
    "            return stu\n",
    "    return None\n",
    "def query():\n",
    "    no = input(\"输入要查询的学号\")\n",
    "    stu = load_stu(no)\n",
    "    print(\"-\"*70)\n",
    "    if stu:\n",
    "        print(format_title.format(\"学号\",\"姓名\",\"年龄\",\"专业\"))\n",
    "        print(format_data.format(stu[\"no\"],stu[\"name\"],stu[\"age\"],stu[\"major\"]))\n",
    "    else:\n",
    "        print(\"*******************查询的学生不存在****************************\")\n",
    "    print(\"-\"*70)\n",
    "def list():\n",
    "    print(\"-\"*70)\n",
    "    if(len(stu_list)>0):\n",
    "        print(format_title.format(\"学号\",\"姓名\",\"年龄\",\"专业\"))\n",
    "        for stu in stu_list:\n",
    "            print(format_data.format(stu[\"no\"],stu[\"name\"],stu[\"age\"],stu[\"major\"]))\n",
    "    else:\n",
    "        print(\"*******************学生数据没有****************************\")\n",
    "    print(\"-\"*70)\n",
    "\n",
    "def update():\n",
    "    no = input(\"请输入要修改的学生学号:\")\n",
    "    stu = load_stu(no)\n",
    "    if stu:\n",
    "        name = input(f\"输入修改的姓名({stu['name']})\")\n",
    "        age = int(input(f\"输入年龄({stu['age']})\"))\n",
    "        major = input(f\"输入专业({stu['major']})\")\n",
    "        stu[\"name\"] = name\n",
    "        stu[\"age\"] = age\n",
    "        stu[\"major\"] = major\n",
    "        print(\"-------------------->更新学生成功<-------------------\")\n",
    "    else:\n",
    "        print(\"*******************更新的学生不存在****************************\")\n",
    "\n",
    "def remove():\n",
    "    no = input(\"请输入删除的学号\")\n",
    "    stu = load_stu(no)\n",
    "    if stu:\n",
    "        stu_list.remove(stu)\n",
    "        print(\"-------------------->删除学生成功<-------------------\")\n",
    "    else:\n",
    "        print(\"*******************删除的学生不存在****************************\")\n",
    "        \n",
    "def main():\n",
    "    while True:\n",
    "        show_operator()\n",
    "        o = input(\"请选择一个操作:\")\n",
    "        if o.upper()=='A':\n",
    "            add()\n",
    "        elif o.upper()=='D':\n",
    "            remove()\n",
    "        elif o.upper()=='U':\n",
    "            update()\n",
    "        elif o.upper()=='Q':\n",
    "            query()\n",
    "        elif o.upper()=='L':\n",
    "            list()\n",
    "        elif o.upper()=='E':\n",
    "            print(\"欢迎使用我们的系统!\")\n",
    "            break;\n",
    "        else:\n",
    "            print(\"请选择一个正确的操作!\")\n",
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d7f54359-3986-4b9b-80d7-c5ad73821b14",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "def fn1(a,b=1):\n",
    "    return a+b\n",
    "\n",
    "c = fn1(2)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "35d99aef-c907-4d3f-b977-73f4f32710f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3]\n"
     ]
    }
   ],
   "source": [
    "b = []\n",
    "def fn2(a,b):\n",
    "    b.append(a)\n",
    "fn2(2,b)\n",
    "fn2(3,b)\n",
    "print(b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "74254625-8f0a-43b6-8605-7feaf529e97f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1326290015216 <class 'type'> 1326323033760 <class '__main__.Student'>\n"
     ]
    }
   ],
   "source": [
    "class Student:\n",
    "    pass\n",
    "stu = Student()\n",
    "print(id(Student),type(Student),id(stu),type(stu))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "060b8735-89b5-4e62-9550-c30939e9b7fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "txt\n"
     ]
    }
   ],
   "source": [
    "s = \"hello world\"\n",
    "s.index('e')\n",
    "s.find('a')\n",
    "fname = \"asdasf.dafsdfa.txt\"\n",
    "pos = fname.rfind(\".\")\n",
    "print(fname[pos+1:])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "431336ec-00e1-41eb-82b4-4802a39f7c3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['d:', 'aa', 'bb', 'd.txt']\n",
      "['d:/aa/bb', 'd.txt']\n"
     ]
    }
   ],
   "source": [
    "filepath = \"d:/aa/bb/d.txt\"\n",
    "lst = filepath.split(\"/\")\n",
    "print(lst)\n",
    "lst = filepath.rsplit(\"/\",maxsplit=1)\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "aef881fd-ef06-4c7e-89bd-6afdf1f9223c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world hello yeah\n",
      "c,c,c,c,c,b\n",
      "a|b|c\n"
     ]
    }
   ],
   "source": [
    "s = \"hello world\"\n",
    "s1 = s.replace(\"world\",\"yeah\")\n",
    "print(s,s1)\n",
    "s = \"a,a,a,a,a,b\"\n",
    "s1 = s.replace(\"a\",\"c\")\n",
    "print(s1)\n",
    "lst = [\"a\",\"b\",\"c\"]\n",
    "ss = '|'.join(lst)\n",
    "print(ss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cc9905a5-2395-4e63-b315-bc92fde49417",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "2507065591664 2507065591664\n"
     ]
    }
   ],
   "source": [
    "a = \"a1001\"\n",
    "b = \"a1001\"\n",
    "print(a is b)\n",
    "print(id(a),id(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "65c3dcfe-7eee-412e-8727-11bf6cec45a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "jk\n",
      "wlx\n",
      "aaa\n",
      "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'classroom']\n",
      "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'age', 'classroom', 'name']\n"
     ]
    }
   ],
   "source": [
    "class Student:\n",
    "    classroom=\"\"\n",
    "    def __init__(self,name,age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "    @classmethod\n",
    "    def a(cls,name):\n",
    "        cls.classroom = name\n",
    "        \n",
    "\n",
    "s1 = Student(\"aa\",12)\n",
    "s2 = Student(\"bb\",33)\n",
    "s1.classroom = \"jk\"\n",
    "print(s2.classroom)\n",
    "print(s1.classroom)\n",
    "Student.classroom = \"wlx\"\n",
    "print(Student.classroom)\n",
    "Student.a(\"aaa\")\n",
    "print(Student.classroom)\n",
    "print(dir(Student))\n",
    "print(dir(s1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "5dc7406c-53c4-4087-ba14-ba3311ea79ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A--a\n",
      "B--a\n",
      "abc\n",
      "{'name': 'abc'}\n",
      "{'__module__': '__main__', 'b': <function B.b at 0x00000247B8604700>, 'a': <function B.a at 0x00000247B8604670>, '__doc__': None}\n",
      "(<class '__main__.A'>, <class '__main__.AA'>)\n",
      "<class '__main__.A'>\n",
      "(<class '__main__.B'>, <class '__main__.A'>, <class '__main__.AA'>, <class 'object'>)\n",
      "[<class '__main__.B'>]\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    def __init__(self,name):\n",
    "        self.name = name\n",
    "    def a(self):\n",
    "        print(\"A--a\")\n",
    "class AA:\n",
    "    pass\n",
    "class B(A,AA):\n",
    "    b = 'abc'\n",
    "    def a(self):\n",
    "        print(\"B--a\")\n",
    "    def b(self):\n",
    "        # self.a()\n",
    "        super().a()\n",
    "        self.a()\n",
    "\n",
    "b = B(\"abc\")\n",
    "b.b()\n",
    "print(b.name)\n",
    "print(b.__dict__)\n",
    "print(B.__dict__)\n",
    "print(B.__bases__)\n",
    "print(B.__base__)\n",
    "print(B.__mro__)\n",
    "print(A.__subclasses__())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "4a774143-055b-454d-8c3e-f13c13f367a8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2507023308112\n",
      "new方法被调用,id:(2507023308112)\n",
      "new-->obj的id是2507069531760\n",
      "init方法被调用，self的id是2507069531760\n",
      "2507069531760\n"
     ]
    }
   ],
   "source": [
    "class Person(object):\n",
    "    def __new__(cls,*args,**kwargs):\n",
    "        print(f\"new方法被调用,id:({id(cls)})\")\n",
    "        obj = super().__new__(cls)\n",
    "        print(f\"new-->obj的id是{id(obj)}\")\n",
    "        return obj\n",
    "\n",
    "    def __init__(self,name,age):\n",
    "        print(f\"init方法被调用，self的id是{id(self)}\")\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "\n",
    "print(id(Person))\n",
    "p = Person(\"zs\",12)\n",
    "print(id(p))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "6418e03d-c0a8-45cd-836d-d2b68a5940f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dell G15\n",
      "Intel I7\n",
      "Nivida H3 is display\n",
      "win10 is start\n",
      "------------------------------\n",
      "Dell G15\n",
      "AMD c5\n",
      "Nivida H3 is display\n",
      "win10 is start\n",
      "------------------------------\n"
     ]
    }
   ],
   "source": [
    "class CPU:\n",
    "    def __init__(self,band):\n",
    "        self.band = band\n",
    "class VideoCard:\n",
    "    def __init__(self,band):\n",
    "        self.band = band\n",
    "\n",
    "class Computer:\n",
    "    def __init__(self,cpu,videoCard,name):\n",
    "        self.cpu = cpu\n",
    "        self.videoCard = videoCard\n",
    "        self.name = name\n",
    "\n",
    "    def startup(self):\n",
    "        print(self.name)\n",
    "        print(self.cpu.band)\n",
    "        print(f\"{self.videoCard.band} is display\")\n",
    "        print(\"win10 is start\")\n",
    "        print(\"-\"*30)\n",
    "\n",
    "cpu = CPU(\"Intel I7\")\n",
    "vc = VideoCard(\"Nivida H3\")\n",
    "computer = Computer(cpu,vc,\"Dell G15\")\n",
    "computer.startup()\n",
    "c1 = computer\n",
    "c1.cpu = CPU(\"AMD c5\")\n",
    "computer.startup()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "44b30583-5c71-4b03-a355-fcfa0071d1aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "华硕\n",
      "I6\n",
      "Nivida H3 is display\n",
      "win10 is start\n",
      "------------------------------\n",
      "Dell G15\n",
      "AMD c5\n",
      "Nivida H3 is display\n",
      "win10 is start\n",
      "------------------------------\n"
     ]
    }
   ],
   "source": [
    "import copy\n",
    "c2 = copy.deepcopy(c1)\n",
    "c2.name = \"华硕\"\n",
    "c2.cpu.band = \"I6\"\n",
    "c2.startup()\n",
    "c1.startup()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34d985bd-d2b7-4654-8e5f-e28b4a56ada2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
